﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Threading;

namespace PInitiatives.Outlook
{
    public class EmailWorkerObserver : Observer
    {
        public EmailWorker emailWorker;
        public Thread emailWorkerThread;

        public EmailWorkerObserver() {
        }

        public void Update(){

            if (emailWorker != null && emailWorkerThread != null)
            {
                //stopping old thread
                emailWorker.StopWork();
                while(!emailWorker.isStopped()){//wait until thread completly stopps
                    Thread.Sleep(100);
                }
                //starting new thread
                emailWorkerThread = new Thread(new ThreadStart(emailWorker.DoWork));
            }
        }

        public void setEmailWorker(EmailWorker ew) {
            emailWorker = ew;
        }

        public void setEmailWorkerThread(Thread ewt) {
            emailWorkerThread = ewt;
        }

        
    }
}